package cn.life.common.utils;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.servlet.view.document.AbstractExcelView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.Map;

/**
 * @Description:
 * @Author 李佳明
 * @Date 2018-09-11 13:57
 */
public class CExportExcelView extends AbstractExcelView {
    protected void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        workbook = (HSSFWorkbook) model.get("workBook");
        String fileName = (String) model.get("fileName");
        String dfileName = null;
        dfileName = new String(fileName.getBytes("GB2312"), "ISO_8859_1");
        //输出Excel文件
        OutputStream output = response.getOutputStream();
        //response.reset();
        response.setHeader("Content-disposition", "attachment; filename=" + dfileName +".xls");
        response.setContentType("application/xls");
        workbook.write(output);
        output.close();
    }
}
